package lumingweihua.future.cn.lumingweihua.ui;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.zhusx.core.app.Lib_BaseActivity;
import com.zhusx.core.utils._Bitmaps;
import com.zhusx.core.utils._Files;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import lumingweihua.future.cn.baselibgxh.utils.AppManager;
import lumingweihua.future.cn.baselibgxh.utils.Base64;

/**
 * Author       zhusx
 * Created      2018/3/15 13:56
 */

public abstract class BaseCompatActivity extends Lib_BaseActivity{
    public static String EXTRA_BOOLEAN_SELECT_MODE = "isSelCar";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getInstance().addActivity(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppManager.getInstance().finishActivity(this);
    }

    public File compressFile(File file) {
        if (!file.exists()) {
            return file;
        }
        File saveFile = new File(getExternalCacheDir(), System.currentTimeMillis() + ".jpg");
        Bitmap b = _Bitmaps.decodeBitmap(file.getPath(), 720, 1280, 100);
        _Files.saveToFile(b, saveFile.getPath());
        if (!b.isRecycled()) {
            b.recycle();
        }
        return saveFile;
    }

    public String toBase64String(File file) {
        if (!file.exists()) {
            return "";
        }
        try {
            FileInputStream fileInputStream = new FileInputStream(file);
            byte[] bytes = new byte[fileInputStream.available()];
            fileInputStream.read(bytes);
            fileInputStream.close();
            return Base64.encode(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    public void showToast(String message) {
        _showToast(message);
    }

    public void onReturn(View v) {
        finish();
    }
}
